package cn.com.miao.lynx.common.data.core;

import com.p6spy.engine.spy.appender.MessageFormattingStrategy;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * P6spyLogFormatter
 * P6SPY日志格式化
 * @title: P6spyLogFormatter
 * @description:
 * @author: dengmiao
 * @create: 2019-12-26 17:13
 **/
public class P6spyLogFormatter implements MessageFormattingStrategy {

    private final static String FORMAT_PATTERN = "yyyy-MM-dd HH:mm:ss";

    @Override
    public String formatMessage(int connectionId, String now, long elapsed, String category, String prepared, String sql, final String url) {
        return !"".equals(sql.trim()) ? "[ " + LocalDateTime.now().format(DateTimeFormatter.ofPattern(FORMAT_PATTERN)) + " ] --- | took "
                + elapsed + "ms | category " + category + " | connectionId " + connectionId + "\n "
                + sql + ";" : "";
    }
}
